home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 40 / Amiga Format CD40 (1999-05-11)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-06].iso / -readerstuff- / paul_qureshi / source / water1.lzx / waterasm.asm < prev   
Assembly Source File  |  1981-09-11  |  3KB  |  137 lines

  1. ;--------------------------------------
  2. ;                Water
  3. ;
  4. ;      (C) 1995 Kimmo Roimela
  5. ;
  6. ; You may use this code for your own
  7. ; productions as you wish, but partial
  8. ; credit would be appreciated...
  9. ;--------------------------------------
  10.  
  11.  
  12. ideal
  13. p386
  14. model small,C
  15.  
  16. codeseg
  17.  
  18. public wave
  19.  
  20. extrn C buffer3_SEG : word
  21. extrn C VGA_SEG : word
  22.  
  23.  
  24. ;-----------------------------------------------
  25. ; wave
  26. ;
  27.  
  28. proc C wave far
  29.     arg DestSEG:word, SrcSEG:word, BlockX:word, BlockY:word, BlockWidth:word, BlockHeight:word
  30.  
  31.     push eax        ; Store the registers used.
  32.     push ebx
  33.     push edx
  34.     push cx
  35.     push si
  36.     push di
  37.     push ds
  38.     push es
  39.     push fs
  40.     push gs
  41.  
  42.     ; Set up the registers:
  43.  
  44.     mov si,[BlockY]        ; Make di point to the correct location
  45.     mov di,si        ; in buffer & video memory:
  46.     shl di,8        ; Multiply by 320...
  47.     shl si,6
  48.     add di,si
  49.     add di,[BlockX]        ; ...and add the initial offset.
  50.     mov cx,di        ; cx always points to the end of the
  51.     add cx,[BlockWidth]        ; line being drawn.
  52.     mov si,[BlockHeight]    ; si counts scanlines left to draw.
  53.     shr si,1
  54.  
  55.     ; Set up the segment registers:
  56.  
  57.     mov ds,[DestSEG]    ; ds -> destination buffer
  58.     mov es,[SrcSEG]        ; es -> source buffer
  59.     mov fs,[buffer3_SEG]    ; fs -> velocity buffer
  60.     mov gs,[VGA_SEG]    ; gs -> video memory
  61.  
  62. loop1:
  63.     ; Calculate the average of the surrounding points.
  64.  
  65.     mov eax,0
  66.     mov ebx,0
  67.  
  68.     mov ax,[word ptr es:di-640]    ; Sum the surrounding points.
  69.     add ebx,eax
  70.     mov ax,[word ptr es:di-2]
  71.     add ebx,eax
  72.     mov ax,[word ptr es:di+2]
  73.     add ebx,eax
  74.     mov ax,[word ptr es:di+640]
  75.     add ebx,eax
  76.  
  77.     sar ebx,2        ; Divide. ebx now contains the average.
  78.  
  79.     ; Calculate the harmonic force caused by the difference between
  80.     ; the current position and the average.
  81.  
  82.     mov ax,[word ptr es:di]
  83.     sub ebx,eax
  84.     add ebx,8    ; Round up, or the thing sort of collapses...
  85.     sar ebx,4
  86.  
  87.     ; Modify the velocity accordingly & calculate the new position.
  88.  
  89.     movsx edx,[word ptr fs:di]    ; Get the current velocity.
  90. ;    mov dx,[word ptr fs:di]        ; Use this if you remove the
  91.                     ; damping below...
  92.  
  93.     mov eax,edx            ; Apply damping factor.
  94.     sal edx,9
  95.     sub edx,eax
  96.     add edx,256
  97.     sar edx,9
  98.  
  99.     add dx,bx            ; Modify with the force.
  100.     mov [fs:di],dx
  101.     mov bx,[word ptr es:di]        ; Update the position.
  102.     add bx,dx
  103.  
  104.     mov [ds:di],bx        ; Write to destination buffer.
  105.  
  106.     mov bl,bh        ; Write to video memory.
  107.     mov [gs:di],bx
  108.     mov [gs:di+320],bx
  109.  
  110.     add di,2        ; Check whether we're done.
  111.     cmp di,cx
  112.  
  113.     jne loop1
  114.  
  115.     sub di,[BlockWidth]    ; Move on to the next scanline.
  116.     add di,640
  117.     add cx,640
  118.     dec si
  119.     jne loop1        ; All done?
  120.  
  121.     pop gs
  122.     pop fs            ; Restore the registers.
  123.     pop es
  124.     pop ds
  125.     pop di
  126.     pop si
  127.     pop cx
  128.     pop edx
  129.     pop ebx
  130.     pop eax
  131.  
  132.     ret
  133.  
  134. endp wave
  135.  
  136. END
  137.